package cn.rkylin.oms.warehouse.stockin.dao;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.warehouse.stockin.domain.StockIn;
import cn.rkylin.oms.warehouse.stockin.domain.StockinType;
import cn.rkylin.oms.warehouse.stockin.vo.StockInVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 入库DAO
 *
 * @author 齐涛
 * @version 1.0
 * @created 11-9-2017 10:51:30
 */
@Repository(value = "stockInDAO")
public class StockInDAOImpl implements StockInDAO {

    @Autowired
    protected IDataBaseFactory dao;

    /**
     * 查询入库单信息
     *
     * @param stockInVO 入库单VO
     * @return 入库单信息
     * @throws Exception 异常
     */
    public StockInVO getStockInInfo(StockInVO stockInVO) throws Exception {
        List<StockInVO> list = dao.findAllList("getStockInInfo", stockInVO);

        if (list != null && list.size() > 0) {
            return list.get(0);
        }

        return null;
    }

    /**
     * 更新入库单
     *
     * @param stockIn 入库单bean
     * @return 更新条数
     * @throws Exception 异常
     */
    public int updateStockIn(StockIn stockIn) throws Exception {
        return dao.update("updateStockIn", stockIn);
    }

    /**
     * 删除入库单
     *
     * @param stockIn 入库单bean
     * @return 删除条数
     * @throws Exception 异常
     */
    public int deleteStockIn(StockIn stockIn) throws Exception {
        return dao.delete("deleteStockIn", stockIn);
    }

    /**
     * 添加入库单
     *
     * @param stockIn 入库单bean
     * @return 添加条数
     * @throws Exception 异常
     */
    public int insertStockIn(StockIn stockIn) throws Exception {
        return dao.insert("insertStockIn", stockIn);
    }

    /**
     * 查询入库单信息(更新在途数)
     *
     * @param stockInVO
     * @return
     * @throws Exception
     */
    public StockInVO getStockInInfoForUpdateOnwayQty(StockInVO stockInVO) throws Exception {
        List<StockInVO> list = dao.findAllList("getStockInInfoForUpdateOnwayQty", stockInVO);

        if (list != null && list.size() > 0) {
            return list.get(0);
        }

        return null;
    }

    /**
     * 查询入库类型列表
     *
     * @return
     * @throws Exception
     */
    public List<StockinType> selectStockinTypeList() throws Exception {
        return dao.findList("selectStockinTypeList", "");
    }

    public int getUnGoingCount(Map<String, String> paramMap) throws Exception{
        return dao.findOne("selectUnGoingStockInCount", paramMap);
    }

}
